<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Functions_model extends CI_Model {

    var $fname   = '';
    var $flink = '';
    var $ffile    = '';
    var $fdate    = '';
    var $factive    = '';

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function getlistfunctions()
    {
    	$this->load->database('default'); 
		$query = $this->db->get('tblfunction');
		if ($query->num_rows() > 0)
        {
          return $query->result();
        } else {
          return array();
        } 
    }
    
 	function getlistfunctions_type($type)
    {
    	$this->load->database('default'); 
		$query = $this->db->get_where('tblfunction',array('ftype'=>$type));
		if ($query->num_rows() > 0)
        {
          return $query->result();
        } else {
          return array();
        } 
    } 
    
    
    function checkexit($modname)
    {
   	 	$this->load->database('default'); 
        $data = array(                
			'fname' => $modname ,                
			'fdate' =>  date("hhmmyy") 
         ); 
        $query = $this->db->get_where('tblfunction',array('fname' => $modname),1,0);
    	if($query->num_rows()>0){	
			 return 1;
		} else {
			return 0;
		}    	
    }

    function insert_functions($modname,$file,$type)
    {
        $this->load->database('default'); 
        $data = array(                
			'fname' => $modname ,                
			'fdate' =>  date("Y-m-d H:i:s"),
        	'ffile' => $file,
        	'ftype' =>  $type 
        ); 
		$this->db->insert('tblfunction', $data);    		
    }

	function deletefunction($id)
    {
    	$this->load->database('default'); 
    	$this->db->delete('tblfunction', array('fid' => $id)); 
    }
    
    function update_entry()
    {
        $this->title   = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date    = time(); 
        $this->db->update('entries', $this, array('id' => $_POST['id']));
    }

    
}